package edu.sctu.chengongsuo.student_activity;

import com.sun.org.apache.xpath.internal.SourceTree;
import javafx.beans.WeakInvalidationListener;

/**
 * Created by user0 on 2015/5/28.
 */
public class Student implements StudentActivity {

    private String name;
    private int age;
    private int gender;

    private CampusCard campusCard;

    public Student(String name, int age, int gender, CampusCard campusCard) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.campusCard = campusCard;
    }

    public void haveLaunch() {

        DinningRoom room = new DinningRoom();

        Window window = selectWindow(room);

        Dish[] dishes = selectDishes(window);

        int amount = 0;

        for (int i = 0; i < dishes.length; i++) {
            amount += dishes[i].getPrice();
        }

        consume(amount);

        int seat = room.getEmptySeat();

        if (seat == -1) {
            System.out.println("-> There is no empty seat.");
        } else {
            System.out.println("-> Your seat no is: " + seat);

        }

    }

    public Window selectWindow(DinningRoom room) {

        return room.getWindows()[0];
    }

    public Dish[] selectDishes(Window window) {

        return window.getDishes();
    }


    public void consume(int amount) {

        if (campusCard.getBalance() < amount) {

            System.out.println("-> Balance is not enough.");

        } else {

            campusCard.setBalance(campusCard.getBalance() - amount);

            System.out.println("-> After consuming the balance is: " + campusCard.getBalance());
        }
    }
}
